
#include "iostream"
#include "vector"
#include "unordered_map"
#include "algorithm"


class Solution {
public:
    void handle(int n) {
        this->n = n;
        construct_buf(n-1);
        putnum();
        print();;
    }

private:
    void putnum() {
        pos_x = 0;
        pos_y = 0;

        int dir = 0;
        int leftstep = n;
        int step = 1;
        while (leftstep > 0) {
            auto movestep = std::min(step, leftstep);
            leftstep -= step;
            switch (dir) {
                case 0:
                    step_move_and_put_num(0, -movestep);
//                    print();
                    break;
                case 1:
                    step_move_and_put_num(movestep, 0);
//                    print();
                    step++;
                    break;
                case 2:
                    step_move_and_put_num(0, movestep);
//                    print();
                    break;
                case 3:
                    step_move_and_put_num(-movestep, 0);
//                    print();
                    step++;
                    break;
            }
            dir++;
            dir %= 4;
        }
    }

    void construct_buf(int n) {

        int dir = 0;
        int leftstep = n;
        int step = 1;
        while (leftstep > 0) {
            auto movestep = std::min(step, leftstep);
            leftstep -= step;
            switch (dir) {
                case 0:
                    move(0, -movestep);
                    break;
                case 1:
                    move(movestep, 0);
                    step++;
                    break;
                case 2:
                    move(0, movestep);
                    break;
                case 3:
                    move(-movestep, 0);
                    step++;
                    break;
            }
            dir++;
            dir %= 4;
        }
        w = maxx - minx + 1;
        h = maxy - miny + 1;
        vec.resize(w);
        for (auto &a:vec) {
            a.resize(h);
        }
    }

    void print() {
        for (int i = h-1; i >= 0; i--) {
            for (int j = 0; j < w; j++) {
                int w1=listw(j);
                if(j!=0){
                    printf(" ");
                }
                    if(vec[j][i]==0){
                        for(int i=0;i<w1;i++){
                            printf(" ");
                        }
                    }else{
                        switch (w1) {
                            case 1:
                                printf("%1d", vec[j][i]);
                                break;
                            case 2:
                                printf("%2d", vec[j][i]);
                                break;
                            case 3:
                                printf("%3d", vec[j][i]);
                                break;
                        }
                    }

            }
            printf("\n");
        }
    }
    int listw(int x){
        int w=1;
        for(int i=0;i<h;i++){
            if(vec[x][i]>=100){
                w=3;
            }else if(vec[x][i]>=10){
                w= std::max(2,w);
            }
        }
        return w;
    }
    std::vector<std::vector<int>> vec;
    int pos_x = 0;
    int pos_y = 0;
    int maxx = 0;
    int minx = 0;
    int maxy = 0;
    int miny = 0;
    int w;
    int h;
    int n;
    int cnt = 1;

    void step_move_and_put_num(int x, int y) {
        int step_cnt;
        if (x != 0) {
            step_cnt = abs(x);
        } else {
            step_cnt = abs(y);
        }


        while (step_cnt) {
            vec[pos_x - minx][pos_y - miny] = cnt;
            if (x > 0) {
                move(1, 0);
            } else if (x < 0) {
                move(-1, 0);
            } else if (y > 0) {
                move(0, 1);
            } else if (y < 0) {
                move(0, -1);
            }
            cnt++;
            step_cnt--;
        }
    }

    void move(int x, int y) {
        pos_x += x;
        pos_y += y;
        if (pos_x > maxx) {
            maxx = pos_x;
        } else if (pos_x < minx) {
            minx = pos_x;
        }
        if (pos_y > maxy) {
            maxy = pos_y;
        } else if (pos_y < miny) {
            miny = pos_y;
        }
    }
};

int main() {
    int i = 0;
    bool first=true;
    while (std::cin >> i) {
        Solution s;
        if(!first){
            printf("\n");
        }
        first=false;
        s.handle(i);

    }
    return 0;
}

